<?php

header('Content-Type: text/html; charset=utf-8');
include_once('facilitador.php');
conexao();
bloqueia();

$ret = "categoria-listar";
$tab = "categoria";

$categoria = strip($_POST['categoria']);



if ($_GET['funcao'] == "Inserir") {
    $sql = $MQ("INSERT INTO ".$tab." VALUES ('','$categoria');");
    echo "<script type='text/javascript'>alert('Cadastro realizado'); window.location = 'index.php?pagina=".$ret."'; </script>";
    exit();
}

/* ############################################################ */

if ($_GET['funcao'] == "Editar") {
    $id = $_GET['id'];
    $sql = $MQ("UPDATE ".$tab." SET cat = '$categoria' WHERE id = '$id'");
    echo "<script type='text/javascript'>alert('Alteração realizada'); window.location = 'index.php?pagina=".$ret."';</script>";
    exit();
}

/* ######################################################### */

if ($_GET['funcao'] == "Excluir") {
    $id = $_GET['id'];
    $sql = $MQ("DELETE FROM ".$tab." WHERE id = '$id'");
    echo "<script type='text/javascript'>alert('Cadastro Excluído.'); window.location = 'index.php?pagina=".$ret." ' ;</script>";
}
/* ############################################################ */
?>